import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { AuthDto } from './dto/wx.dto';
import { WX_CONFIG } from '../../config';

@Injectable()
export class WxService {
  constructor(private readonly httpService: HttpService) {}

  async auth(authDto: AuthDto): Promise<any> {
    const code = authDto.code;
    const { appid, secret } = WX_CONFIG;
    const url = `https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appid}&secret=${secret}&code=${code}&grant_type=authorization_code`;
    const result = await this.httpService.axiosRef.get(url);
    return result.data;
  }
}
